package com.cabd.service.impl;

import java.io.File;
import java.sql.SQLException;
import java.util.List;

import com.cabd.dao.FolderDao;
import com.cabd.dao.impl.FolderDaoImpl;
import com.cabd.domain.Folder;
import com.cabd.service.FolderService;
import com.cabd.staticfinal.DownLoadAndUpLoadPath;

public class FolderServiceImpl implements FolderService {
	
	@Override
	public void addService(Folder folder) {
		FolderDao folderDao = new FolderDaoImpl();
		try {
			folderDao.add(folder);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void deleteDataBase(Folder folder) {
		FolderDao folderDao = new FolderDaoImpl();
		try {
			folderDao.delete(folder);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	@Override
	public List<Folder> findAllService() {
		FolderDao folderService = new FolderDaoImpl();
		List<Folder> folders = null;
		try {
			folders = folderService.findAll();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return folders;
	}

	@Override
	public void deleteFiles(String folderName) {
		String path = DownLoadAndUpLoadPath.downLoadAndUpLoadPath+"\\"+folderName;
		System.out.print("刪除文件："+folderName+"---");
		String path1 = DownLoadAndUpLoadPath.downLoadAndUpLoadPath+"\\"+folderName+"\\output";
		File file1 = new File(path1);
		for(File eFile:file1.listFiles()) {
			System.out.println(eFile+", ");
			eFile.delete();
		}
		file1.delete();
		File file = new File(path);
		for(File eFile:file.listFiles()) {
			System.out.println(eFile+", ");
			eFile.delete();
		}
		
		file.delete();
		System.out.println();
	}

}
